local more1__jijin = fk.CreateSkill {
  name = "more1__jijin",
}

Fk:loadTranslationTable{
  ["more1__jijin"] = "继荆",
  [":more1__jijin"] = "每回合限X次，当你使用牌指定目标后，你可以将其至多X张牌扣置于该角色的武将牌旁，若如此做，"..
  "当前回合结束时，该角色获得这些牌。（X为全场势力数+1）",

  ["#more1__jijin-invoke"] = "继荆：是否扣置%dest的至多%arg张牌直到回合结束",
  ["$more1__jijin"] = "继荆",

  ["$more1__jijin1"] = "",
  ["$more1__jijin2"] = "",
}
  
more1__jijin:addEffect(fk.TargetSpecified, {
  anim_type = "control",
  times = function(self, player)
    local kingdoms = {}
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      table.insertIfNeed(kingdoms, p.kingdom)
    end
    return #kingdoms+1-player:usedEffectTimes(self.name)
  end,
  can_trigger = function(self, event, target, player, data)
    local kingdoms = {}
    for _, p in ipairs(player.room.alive_players) do
      table.insertIfNeed(kingdoms, p.kingdom)
    end
    return target == player and player:hasSkill(more1__jijin.name) and data.card and
      not data.to.dead and not data.to:isNude() and player:usedEffectTimes(self.name, Player.HistoryTurn) < #kingdoms + 1 and data.to ~= player
  end,
  on_cost = function(self, event, target, player, data)
    local kingdoms = {}
    for _, p in ipairs(player.room.alive_players) do
      table.insertIfNeed(kingdoms, p.kingdom)
    end
    if player.room:askToSkillInvoke(player, {
      skill_name = more1__jijin.name,
      prompt = "#more1__jijin-invoke::" .. data.to.id .. ":" .. (#kingdoms+1),
    }) then
      event:setCostData(self, {tos = {data.to}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local kingdoms = {}
    for _, p in ipairs(player.room.alive_players) do
      table.insertIfNeed(kingdoms, p.kingdom)
    end
    local cards = room:askToChooseCards(player, {
      target = data.to,
      flag = "he",
      skill_name = more1__jijin.name,
      min = 1,
      max = (#kingdoms+1)
    })
    data.to:addToPile("$more1__jijin", cards, false, self.name, player.id)
  end,
})

more1__jijin:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and #player:getPile("$more1__jijin") > 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("$more1__jijin"), Player.Hand, player, fk.ReasonPrey, more1__jijin.name)
  end,
})

return more1__jijin
